package com.shanghai.shanghaielectric.UI.chart;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.shanghai.shanghaielectric.R;
import com.shanghai.shanghaielectric.UI.event.EventErrorFragment;
import com.shanghai.shanghaielectric.UI.event.EventWarningFragment;
import com.shanghai.shanghaielectric.UI.FragmentTabAdapter_Main;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 45000460 on 2017/12/21.
 */

public class ChartDatabaseFragment extends Fragment {
    private RadioGroup chartrgs;
    public List<Fragment> chartfragments = new ArrayList<Fragment>();
    public View chartView;
    private EventErrorFragment eventError;
    private EventWarningFragment eventWarning;
    private int pause = 0;
    private RadioButton radio_chart_report;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        System.out.println("Event____onAttach");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("Event____onCreate");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        System.out.println("Event____onCreateView");
        chartView = inflater.inflate(R.layout.chart_databasefragment, container,
                false);
        pause = 0;
        radio_chart_report = (RadioButton) chartView.findViewById(R.id.radio_chart_report);
        radio_chart_report.setChecked(true);
        chartfragments.add(new ChartReportFragment());
        chartfragments.add(new Chart_capacityCuttingFragment());
        chartfragments.add(new ChartFragment_chart());
        chartfragments.add(new ChartFragment_THD());
        chartrgs = (RadioGroup) chartView
                .findViewById(R.id.tabs_chart_chart_rg);

        FragmentTabAdapter_Main tabAdapter = new FragmentTabAdapter_Main(
                this.getActivity(), chartfragments, R.id.tab_chart_content,
                chartrgs);
        tabAdapter
                .setOnRgsExtraCheckedChangedListener(new FragmentTabAdapter_Main.OnRgsExtraCheckedChangedListener() {
                    @Override
                    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup,
                                                         int checkedId, int index) {
                        System.out.println("Extra---- " + index
                                + " checked!!! ");
                    }
                });

        return chartView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        System.out.println("Event____onActivityCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        System.out.println("Event____onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
//        if (pause == 1) {
//            pause = 0;
//            radio_chart_report.setChecked(true);
//            if (eventError.isAdded()) {
//                eventError.onResume(); // 启动目标tab的onResume()
//            }
//        }
        System.out.println("Event____onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
//        pause = 1;
//        if (eventError.isAdded()) {
//            eventError.onPause(); // 启动目标tab的onResume()
//        }
        System.out.println("Event____onPause");
    }


    @Override
    public void onStop() {
        super.onStop();
        System.out.println("Event____onStop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        System.out.println("Event____onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        System.out.println("Event____onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        System.out.println("Event____onDetach");
    }
}
